package leetcode.秋招.小红书;

import java.util.Scanner;

/**
 * @author ：zsy
 * @date ：Created 2021/8/21 10:56
 * @description：
 */
public class Main {
    static int[][] grid;
    static int R, C;
    static int tr, tc, target;
    static Integer[][][] memo;
    static int[]dr = new int[]{0, -1, 0, 1};
    static int[]dc = new int[]{1, 0, -1, 0};
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int N = in.nextInt();
        grid = new int[N][N];
        for (int i = 0; i < N; i++) {
            String next = in.next();
            for (int j = 0; j < next.length(); j++) {
                if (next.charAt(j) == '.') {
                    grid[i][j] = 0;
                } else
                    grid[i][j] = -1;
            }
        }
        R = C = N;
        target = 0;
        grid[0][0] = 1;
        int ans = 0;
        for (int i = 0; i < N; i++) {
            grid[N - 1][i] = 2;
            int sr = 0, sc = 0;
            for (int r = 0; r < R; r++)
                for (int c = 0; c < C; c++) {
                    if (grid[r][c] % 2 == 0) {
                        target |= code(r, c);
                    }
                    if (grid[r][c] == 1) {
                        sr = r;
                        sc = c;
                    } else if (grid[r][c] == 2) {
                        tr = r;
                        tc = c;
                    }
                }
            memo = new Integer[R][C][1 << R * C];
            ans += dp(sr, sc, target);
            grid[N - 1][i] = 0;
        }
        System.out.println(ans);
    }

    private static Integer dp(int r, int c, int todo) {
        if (memo[r][c][todo] != null) {
            return memo[r][c][todo];
        }
        if (r == tr && c == tc) {
            return todo == 0 ? 1 : 0;
        }
        int ans = 0;
        for (int k = 0; k < 4; k++) {
            int nr = r + dr[k];
            int nc = c + dc[k];
            if (0 <= nr && nr < R && 0 <= nc && nc < C) {
                if ((todo & code(nr, nc)) != 0) {
                    ans += dp(nr, nc, todo ^ code(nr, nc));
                }
            }
        }
        memo[r][c][todo] = ans;
        return ans;
    }

    private static int code(int r, int c) {
        return 1 << (r * C + c);
    }
}
